import axios from 'axios'
// 创建 axios 实例
const instance = axios.create({
  timeout: 5000,
})

// GET 请求封装
const getRequest = (url, params = {}) => {
  return instance
    .get(url, { params })
    .then((response) => response.data)
    .catch((error) => {
      console.error('GET 请求出错:', error)
      throw error
    })
}
// POST 请求封装
const postRequest = (url, data = {}) => {
  return instance
    .post(url, data)
    .then((response) => response.data)
    .catch((error) => {
      console.error('POST 请求出错:', error)
      throw error
    })
}

export { getRequest, postRequest }
